﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{

    public partial class Form1 : Form
    {
        int level;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(SqlHelper.Constr);
            connection.Open();
            string name = textBox1.Text;
            string pass = textBox2.Text;

            string constr = "select level from [user] where userid='" + name + "'and password='" + pass + "';";
            using (SqlCommand command = new SqlCommand(constr, connection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        level = Convert.ToInt32(reader[0]);
                        if (level == 1)
                        {
                            Form4 form4 = new Form4();
                            form4.ShowDialog();
                            break;
                        }
                        else if (level == 2)
                        {
                            Form3 form3 = new Form3();
                            form3.ShowDialog();
                            break;
                        }
                        else
                        {
                            MessageBox.Show("用户名/密码错误");
                            break;
                        }
                    }

                }
            }

            connection.Close();


        }
        public class User
        {
            public int Id { get; set; }
            public string Account { get; set; }
            public string Password { get; set; }
            public int Level { get; set; }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }
    }
}

